// SSITemplateMain.cpp
// author: Johannes Wagner <johannes.wagner@informatik.uni-augsburg.de>
// created: xxxx/xx/xx
// Copyright (C) University of Augsburg

#include "ssi.h"
#include "MotionTrigger.h"
using namespace ssi_sensor;
using namespace ssi_frame;
using namespace ssi_graphic;
using namespace ssi_ioput;
using namespace ssi_signal;

#ifdef USE_SSI_LEAK_DETECTOR
#include "SSI_LeakWatcher.h"
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#ifdef USE_VLD_LEAK_DETECTOR
#include "vld.h"
#endif

int main (int argc, char **argv) {

#ifdef USE_SSI_LEAK_DETECTOR
	{
#endif

		char info[1024];
		ssi_sprint (info, "\n%s\n\nbuild version: %s\n\n", SSI_COPYRIGHT, SSI_VERSION);
		TheFramework::Instance ()->SetAutoThread (true);


		ssi_time_t sample_rate = 80.0;
		ssi_time_t packet_size = 0.5;

		Provider mouse_p;
		MouseSensor mouse (&mouse_p, 0, sample_rate, packet_size);

		ssi_real_t l = 0.2f, r = 0.6f, u = 0.2f, b = 0.6f;

		MotionTrigger trigger (20,15,l, r, u, b);
		Consumer trigger_c (mouse_p.getBufferId (), &trigger, 0.2);

		int plot_id = ThePainter::Instance ()->AddCanvas ("MotionTrigger (triggered)");
		Plotter<ssi_real_t> plot_mouse (plot_id, PAINT_TYPE_PATH);
		Consumer plot_mouse_c (mouse_p.getBufferId (), &plot_mouse, &trigger);

		HWND desktop = ::GetDesktopWindow ();
		RECT rect;
		::GetWindowRect (desktop, &rect);

		mouse.start ();

		ThePainter::Instance ()->Move (plot_id, 
			static_cast<int> (l * rect.right), 
			static_cast<int> (u * rect.bottom), 
			static_cast<int> ((r-l) * rect.right), 
			static_cast<int> ((b-u) * rect.bottom));

		TheFramework::Instance ()->Start ();
		ssi_print ("Press enter to stop!\n");
		getchar ();
		mouse.stop();
		TheFramework::Instance ()->Stop ();
		TheFramework::Instance ()->Shutdown ();

#ifdef USE_SSI_LEAK_DETECTOR
	}
	_CrtDumpMemoryLeaks();
#endif

	return 0;
}
